package swu.cx.fragmentlearning

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
    private lateinit var navController: NavController
    private lateinit var appBarConfiguration: AppBarConfiguration
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        navController=findNavController(R.id.nav_host_fragment)
        bottomNavigationView.setupWithNavController(navController)
        //设置ActionBar
        setSupportActionBar(toolbar)
        //设置toolBar菜单选项，setOf里面的界面表示顶层同级，没有返回键
        appBarConfiguration = AppBarConfiguration(setOf(R.id.homeFragment,R.id.registerFragment),
            drawer
        )
        setupActionBarWithNavController(navController,appBarConfiguration)
        //关联NavigationView和NavController
        nav_view.setupWithNavController(navController)


//        mAdd.setOnClickListener {
//            supportFragmentManager.beginTransaction()
//                .add(R.id.container,LoginFragment())
//                .addToBackStack(null)
//                .commit()
//        }
//        mReplace.setOnClickListener {
//            supportFragmentManager.beginTransaction()
//                .setCustomAnimations(R.anim.slide_in,R.anim.slide_out,R.anim.pop_in,R.anim.pop_out)
//                .replace(R.id.container,RegisterFragment())
//                .commit()
//        }
    }

    override fun onSupportNavigateUp(): Boolean {
        return navController.navigateUp(appBarConfiguration)
    }
}